<?php
/**
 * Proposito General.
 * 
 * @package		CodeIgniter
 * @author		3WD - Tomas Losis <tomas.losis@treswd.com>
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------


if ( !function_exists('get_header'))
{
	function get_header($view = 'header')
	{
		$CI =& get_instance();
		$CI->load->view($view);
	}
}

if ( ! function_exists('get_footer'))
{
	function get_footer($view = 'footer')
	{
		$CI =& get_instance();
		$CI->load->view($view);
	}
}

if ( ! function_exists('get_menu'))
{
	function get_menu($view = 'menu-header')
	{
		$CI =& get_instance();
		
		if($view == 'menu-header'){			
			$data['class_menu_father'] = class_header_menu($CI, 'father');
			$data['class_menu_child_ul'] = class_header_menu($CI, 'child_ul');
			$data['class_menu_child_li'] = class_header_menu($CI, 'child_li');
			$CI->load->view($view,$data);
		} else		
			$CI->load->view($view);
			//array_slice()

	}
}

if ( ! function_exists('get_sidebar'))
{
	function get_sidebar($view = 'sidebar')
	{
		$CI =& get_instance();
		$CI->load->view($view);
	}
}

	function class_header_menu($CI, $menu ='father')
{
	
	$controlador = $CI->uri->segment(1);
	$metodo = $CI->uri->segment(2);

	//echo "el controlador es: $controlador y el metodo es: $metodo";

	switch ($menu){
		case 'father':
				$class_menu = array(
				'home'=>'select',
				'accounts'=>'select',
				'project'=>'select',
				'customer'=>'select',
				'configuration'=>'select',
				'log'=>'select');
				
				$class_menu[$controlador]= "current";
		break;
		case 'child_li':
				$class_menu = array(
				'home_open'=>'',
				'home_close'=>'',
				'home_add'=>'',
				'accounts_view'=>'',
				'accounts_add'=>'',
				'project_view'=>'',
				'project_add'=>'',				
				'customer_view'=>'',
				'customer_add'=>'',				
				'configuration_view'=>'',
				'log_view'=>'');
				
				if (empty($metodo)){
					switch ($controlador){
						case 'home':
							$metodo = "open";
						break;
						case 'accounts':
							$metodo = "view";
						break;
						case 'project':
							$metodo = "view";
						break;
						case 'customer':
							$metodo = "view";
						break;
						case 'configuration':
							$metodo = "view";
						break;
						case 'log':
							$metodo = "view";
						break;						
					}				
				}				
				
				$key = $controlador."_".$metodo;
				$class_menu[$key]= "sub_show";
		break;
		case 'child_ul':
				$class_menu = array(
				'home'=>'select_sub',
				'accounts'=>'select_sub',
				'project'=>'select_sub',
				'customer'=>'select_sub',
				'configuration'=>'select_sub',
				'log'=>'select_sub');				
				
				$class_menu[$controlador]= "select_sub show";				
		break;		
	}

	
	return $class_menu;
}
